var ns, app, WXPhotoPicker;
app = new Vue({
    el: '#app',
    data: {
        tabList: [
            { ID: 1, Name: '待处理' },
            { ID: 2, Name: '新增' },
            { ID: 3, Name: '数据' },
        ],
        activeTab: 0,
        //待处理
        showsearchparamone: false,
        IsShowSearchOne: false,
        //分页
        is_searching_one:false,
        can_scroll_one:false,
        onecurrent_item_length:0,
        scroll_top_one: 0,
        WaitingCount:0,
        formone: {
            pageindex: 0,
            pagesize: 100,
            keywords: '',
            startTime: '',
            endTime: '',
            activeDate: 0,
            ProjectIDs: [],
            VisitTypeIDs: [],
        },
        OneList: [],
        //新增
        formtwo: {
            ID: 0,
            ProjectID: 0,
            ProjectName: '',
            RoomID: 0,//房间ID
            OwnerName: '',//住户名称
            PhoneNumber: '',//住户电话
            VisitType: '',//---通行事由id
            VisitTypeName:'',//通行事由
            ItemInformation:'',//物品信息
            VehicleInformation:'',//车辆信息
            StartTime: '',//通行时间
            EndTime: '',
            ReleaseInstructions: '',//放行说明
            FullName: '',//资源位置
            Type:'2',//类型 1-内部单位 2-外部单位
            ApplyCompany:'',//申请单位
        },
        IsVisitTypeOpen: false,
        typelist2: [],
        imglist: [],
        maxuploadcount: CONFIG.maxuploadcount,
        IsProjectOpen: false,
        ProjectList: [],
        minDate: new Date(),
        maxDate: new Date(2050, 0, 1),
        IsShowStartTime: false,
        IsShowEndTime: false,
        showStartTime: '',
        showEndTime: '',
        //数据
        searchProjectList: [],
        showsearchparam: false,
        IsShowSearchThird: false,
        is_searching_third:false,
        can_scroll_third:false,
        thirdcurrent_item_length:0,
        scroll_top_third:0,
        formthird: {
            pageindex: 0,
            pagesize: 100,
            keywords: '',
            startTime: '',
            endTime: '',
            activeDate: 0,
            ProjectIDs: [],
            VisitTypeIDs: [],
            StatusIDs:[],
        },
        StatusList:[{ID:0,Name:'全部'},{ID:1,Name:'审核中'},{ID:2,Name:'审核拒绝'},{ID:3,Name:'未放行'},{ID:4,Name:'已放行'},{ID:5,Name:'已失效'}],
        thirdList: [],
    },
    methods: {
        onClickTab(index, title) {
            var that=this;
            this.doCloseSearchOne();
            this.doCloseSearchThird();
            if (this.activeTab == 0) {
                that.get_data_one();
            }
            if (this.activeTab == 1) {
                //默认访客为有效期为当天24点前。有效次数1.
                this.showStartTime = moment().format("YYYY/MM/DD HH:mm");
                this.showEndTime = moment().format("YYYY/MM/DD 23:59");
                this.formtwo.StartTime = new Date(this.showStartTime);
                this.formtwo.EndTime = new Date(this.showEndTime);
            }
            if (this.activeTab == 2) {
                that.get_data_third();
            }
        },
        get_data() {
            this.get_project_list();
            this.get_data_two();
            this.getSearchParams();

            this.get_data_one();
        },
        //待处理
        handleEnterOne(event) {
            // 检查按下的键是否是Enter
            if (event.keyCode == 13) {
                this.doSearchOne();
            }
        },
        doSearchClear() {
            this.formone.keywords = '';
            this.doSearchOne();
        },
        get_data_one: function () {
            var that = this;
            var options = {};
            options.pagesize = that.formone.pagesize;
            options.pageindex = that.formone.pageindex;
            options.Type = 1;//1-待处理 2-数据
            options.ProjectIDs =JSON.stringify(that.formone.ProjectIDs);
            options.VisitTypeIDs = JSON.stringify(that.formone.VisitTypeIDs);
            options.keyWords = that.formone.keywords;
            options.StartTime = that.formone.startTime;
            options.EndTime = that.formone.endTime;
            var StatusIDs=[];
            StatusIDs.push(1);
            options.States=JSON.stringify(StatusIDs);
            options.action = "getreleasestripvisitdata";
            ns.post(options, function (succeed, data, err) {
                if (succeed) {
                    that.OneList = data.list;
                } else if (err) {
                    api.toast({
                        msg: err,
                        duration: 2000,
                        location: 'bottom'
                    });
                }
            }, {
                toast: true
            });
        },
        open_details: function (item) {
            ns.openWin('outdoor_detail','放行条详情',{
                ID:item.ID
            });
        },
         //审批
         examRelease:function(item,IsReject){
            var that=this;
            var that = this;
            ns.openWin('examine_single', '审批建议', {
                IsReject: IsReject,
                ID: item.ID,
            });   
        },
        //待处理-筛选
        doClickSearchOne() {
            var that = this;
            that.showsearchparamone = !that.showsearchparamone;
            this.IsShowSearchOne = !this.IsShowSearchOne;
            if (this.IsShowSearchOne) {
                setTimeout(function () {
                    that.initPickerOne();
                }, 100);
            }
        },
        doCloseSearchOne() {
            this.showsearchparamone = false;
            this.IsShowSearchOne = false;
        },
        doResetOne: function () {
            var that = this;
            that.formone.startTime = '';
            that.formone.endTime = '';
            that.formone.activeDate = 0;
            that.formone.ProjectIDs = [];
            that.formone.VisitTypeIDs = [];
        },
        doSearchOne: function () {
            var that = this;
            that.doCloseSearchThird();
            that.get_data_one();
        },
        doSearchProjectOne: function (ID, Name) {
            var that = this;
            that.formone.ProjectIDs = [];
            that.formone.ProjectIDs.push(ID);
        },
        doSearchVisitTypeOne: function (ID, Name) {
            var that = this;
            that.formone.VisitTypeIDs = [];
            that.formone.VisitTypeIDs.push(ID);
        },
        doClickDayOne: function (dataValue) {
            var that = this;
            that.formone.activeDate = dataValue;
            var startDate = '',
                endDate = '';
            if (dataValue == 1) {
                var currentDate = dateRangeUtil.getCurrentDate();
                startDate = moment(new Date()).subtract(3, 'days').format("YYYY-MM-DD");
                endDate = dateRangeUtil.getDateString(currentDate);
            }
            if (dataValue == 2) {
                var currentDate = dateRangeUtil.getCurrentDate();
                startDate = moment(new Date()).subtract(7, 'days').format("YYYY-MM-DD");
                endDate = dateRangeUtil.getDateString(currentDate);
            }
            if (dataValue == 3) {
                var currentDate = dateRangeUtil.getCurrentDate();
                startDate = moment(new Date()).subtract(30, 'days').format("YYYY-MM-DD");
                endDate = dateRangeUtil.getDateString(currentDate);
            }
            that.formone.startTime = startDate;
            that.formone.endTime = endDate;
        },
        initPickerOne: function () {
            var _this = this;
            (function ($, doc) {
                $.init();
                $.ready(function () {
                    //开始日期
                    var btn = document.querySelector('#startdateone');
                    btn.addEventListener('tap', function () {
                        var _self = this;
                        if (_self.picker) {
                            if (_this.formone.startTime) {
                                _self.picker.setSelectedValue(_this.formone.startTime);//回显
                            }
                            _self.picker.show(function (rs) {
                                _this.formone.startTime = rs.value;
                                _self.picker.dispose();
                                _self.picker = null;
                            });
                        } else {
                            var optionsJson = this.getAttribute('data-options') || '{}';
                            var options = JSON.parse(optionsJson);
                            var id = this.getAttribute('id');
                            _self.picker = new $.DtPicker(options);
                            if (_this.formone.startTime) {
                                _self.picker.setSelectedValue(_this.formone.startTime);//回显
                            }
                            _self.picker.show(function (rs) {
                                var timer = setTimeout(function () {
                                    clearTimeout(timer);
                                    _this.formone.startTime = rs.value;
                                }, 300);
                                _self.picker.dispose();
                                _self.picker = null;
                            });
                        }
                    }, false);
                    //结束日期
                    var btnEnd = document.querySelector('#enddateone');
                    btnEnd.addEventListener('tap', function () {
                        var _self = this;
                        if (_self.picker) {
                            if (_this.formone.endTime) {
                                _self.picker.setSelectedValue(_this.formone.endTime);//回显
                            }
                            _self.picker.show(function (rs) {
                                _this.formone.endTime = rs.value;
                                _self.picker.dispose();
                                _self.picker = null;
                            });
                        } else {
                            var optionsJson = this.getAttribute('data-options') || '{}';
                            var options = JSON.parse(optionsJson);
                            var id = this.getAttribute('id');
                            _self.picker = new $.DtPicker(options);
                            if (_this.formone.endTime) {
                                _self.picker.setSelectedValue(_this.formone.endTime);//回显
                            }
                            _self.picker.show(function (rs) {
                                var timer = setTimeout(function () {
                                    clearTimeout(timer);
                                    _this.formone.endTime = rs.value;
                                }, 300);
                                _self.picker.dispose();
                                _self.picker = null;
                            });
                        }
                    }, false);
                });
            })(mui, document);
        },
        //新增 
        //选择项目
        get_project_list: function () {
            var that = this;
            var options = {
                action: 'getmytopprojectlist'
            };
            ns.post(options, function (succeed, data, err) {
                if (succeed) {
                    that.ProjectList = data.list;
                    that.doSelectProject(that.ProjectList[0])
                }
            });
        },
        do_chooseProject: function () {
            var that = this;
            that.IsProjectOpen = true;
        },
        doCloseProject: function () {
            var that = this;
            that.IsProjectOpen = false;
        },
        doSelectProject: function (item) {
            var that = this;
            that.IsProjectOpen = false;
            that.formtwo.ProjectID = item.ID;
            that.formtwo.ProjectName = item.Name;
            // that.get_relation_name();
        },
        get_relation_name: function () {
            var that = this;
            var options = {};
            options.action = 'getroomrelationdata';
            options.ProjectID = that.formtwo.ProjectID
            ns.post(options, function (succeed, data, err) {
                if (succeed) {
                    that.formtwo.OwnerName = data.RealName;
                    that.formtwo.PhoneNumber = data.PhoneNumber;
                }
            });
        },
        do_select_project: function () {
            var that = this;
            ns.openWin('chooseproject_frm', '选择项目');
        },
        get_select_project: function (data) {
            var that = this;
            that.formtwo.RoomID = data.roomid;
            that.formtwo.FullName = data.name;
            that.formtwo.ProjectID = data.projectid;
            that.formtwo.ApplyCompany = data.name;
            that.getRoomOwner();
        },
        getRoomOwner: function () {
            var that = this;
            if(!that.formtwo.RoomID){
                return;
            }
            ns.get({ action: 'getroomrelationdata', ProjectID: that.formtwo.RoomID }, function (succeed, data, err) {
                if (succeed) {
                    that.formtwo.OwnerName = data.RealName;
                    that.formtwo.PhoneNumber = data.PhoneNumber;
                }
            });
        },
        //选择通行事由
        get_data_two: function () {
            var that = this;
            var options = {};
            options.action = "getvisittypelist";
            ns.post(options, function (succeed, data, err) {
                if (succeed) {
                    that.typelist2 = data.list2;
                    if (that.typelist2.length > 0) {
                        that.doSelectVisitType(that.typelist2[0]);
                    }
                } else if (err) {
                    api.toast({
                        msg: err,
                        duration: 2000,
                        location: 'bottom'
                    });
                }
            });
        },
        do_chooseVisitType: function () {
            var that = this;
            that.IsVisitTypeOpen = true;
        },
        doCloseVisitType: function () {
            var that = this;
            that.IsVisitTypeOpen = false;
        },
        doSelectVisitType: function (item) {
            var that = this;
            that.IsVisitTypeOpen = false;
            that.formtwo.VisitType=item.ID;
            that.formtwo.VisitTypeName=item.Name;

        },
        //有效-开始时间
        doOpenStartTime() {
            this.IsShowStartTime = true;
        },
        onChooseStartTime(e) {
            var that = this;
            that.formtwo.StartTime = e;
            that.showStartTime = moment(e).format("YYYY/MM/DD HH:mm");
            //当开始日期大于结束日期时
            if (that.showStartTime != '' && that.showEndTime != '') {
                var diff = moment(that.showEndTime).diff(moment(that.showStartTime), 'minutes');
                if (diff <= 0) {
                    that.showEndTime = moment(e).format("YYYY/MM/DD HH:59");
                    that.formtwo.EndTime = new Date(that.showEndTime);
                }
            }
            that.doCloseStartTime();
        },
        doCloseStartTime() {
            this.IsShowStartTime = false;
        },
        //有效-结束时间
        doOpenEndTime() {
            this.IsShowEndTime = true;
        },
        onChooseEndTime(e) {
            var that = this;
            that.formtwo.EndTime = e;
            that.showEndTime = moment(e).format("YYYY/MM/DD HH:mm");
            that.doCloseEndTime();
        },
        doCloseEndTime() {
            this.IsShowEndTime = false;
        },
        choose_picture: function () {
            var that = this;
            ns.confirmPer('camera', function () {
                that.choose_picture_start();
            })
        },
        choose_picture_start: function () {
            var that = this;
            if (that.imglist.length >= that.maxuploadcount) {
                api.toast({
                    msg: '最多支持' + that.maxuploadcount + '张图片',
                    duration: 2000,
                    location: 'bottom'
                });
                return;
            }
            api.actionSheet({
                cancelTitle: '取消',
                buttons: ['拍照', '从相册选择']
            }, function (ret, err) {
                //拍照
                if (ret.buttonIndex == 1) {
                    that.upload_choose_picture();
                    return;
                }
                //从相册选择
                if (ret.buttonIndex == 2) {
                    that.choose_picture_album();
                    return;
                }
                //取消 
                else {
                    return false;
                }
            });
        },
        upload_choose_picture: function () {
            var that = this;
            api.getPicture({
                sourceType: 'camera',
                encodingType: 'jpg',
                destinationType: 'url',
                allowEdit: false,
                saveToPhotoAlbum: true,
            }, function (ret, err) {
                if (ret && ret.data) {
                    that.do_imageFilter(ret.data);
                    // that.imglist.push({
                    //     ID: 0,
                    //     url: ret.data,
                    //     thumbPath: ret.data,
                    //     isupload: true
                    // });
                }
            });
        },
        choose_picture_album: function () {
            var that = this;
            WXPhotoPicker.open({
                max: that.maxuploadcount - that.imglist.length,
                type: 'image',
            }, function (ret) {
                if (ret) {
                    if (ret.list.length > 0) {
                        ret.list.forEach((item) => {
                            that.do_imageFilter(item.path);
                            // that.imglist.push({
                            //     ID: 0,
                            //     url: item.path,
                            //     thumbPath: item.path,
                            //     isupload: true
                            // });
                        });
                    }
                }
            });
        },
         //图片压缩
         do_imageFilter:function(path){
            var that=this;
            var imgName = Date.now() + '.jpg';
            var target_w = 500;
            var imageFilter = api.require('imageFilter');
            imageFilter.getAttr({
                path: path
            }, function(ret, err) {
                if (ret.status) {
                    if (ret.width < target_w) {
                        target_w = ret.width;
                    }
                    var original_w = ret.width;
                    var original_h = ret.height;
                    var scale = original_w / target_w;
                    var target_h = Math.round(original_h / scale);
                    imageFilter.compress({
                        img: path,
                        quality: 1,
                        size: {
                            w: target_w,
                            h: target_h
                        },
                        save: {
                            album: false,
                            imgPath: api.cacheDir + '/upload/',
                            imgName: imgName
                        }
                    }, function(ret, err) {
                        if (ret.status) {
                            var imgFullName=api.cacheDir + '/upload/' + imgName;
                            that.imglist.push({
                                ID: 0,
                                url: imgFullName,
                                thumbPath: imgFullName,
                                isupload: true
                            });
                        }else{
                            alert( JSON.stringify( err ) );
                        }
                    });
                }
            });
        },
        remove_img: function (index, item) {
            var that = this;
            that.imglist.splice(index, 1);
        },
        do_viewimages: function (activeIndex) {
            var that = this;
            var imageUrls = [];
            for (var i = 0; i < that.imglist.length; i++) {
                imageUrls.push(that.imglist[i].url);
            }
            var imageBrowser = api.require('imageBrowser');
            imageBrowser.openImages({
                showList: false,
                activeIndex: activeIndex,
                imageUrls: imageUrls
            });
        },
        checknumber: function (str) {
            var re = /^[0-9a-zA-Z]*$/g; //判断字符串是否为数字和字母组合
            if (!re.test(str)) {
                return false;
            } else {
                return true;
            }
        },
        do_save: function () {
            var that = this;
            if (that.formtwo.RoomID<=0) {
                api.toast({
                    msg: '请选择资源位置',
                    duration: 2000,
                    location: 'bottom'
                });
                return;
            }
            if (!that.formtwo.OwnerName) {
                api.toast({
                    msg: '请填写住户名称',
                    duration: 2000,
                    location: 'bottom'
                });
                return;
            }
            if (that.formtwo.PhoneNumber == "") {
                api.toast({
                    msg: '请填写手机号码',
                    duration: 2000,
                    location: 'bottom'
                });
                return;
            }
            if (!that.formtwo.VisitTypeName) {
                api.toast({
                    msg: '请选择通行事由',
                    duration: 2000,
                    location: 'bottom'
                });
                return;
            }
            let compareTime = new Date(that.formtwo.EndTime) - new Date(that.formtwo.StartTime);
            if (compareTime <= 0) {
                ns.toast('有效结束时间不能小于等于有效开始时间');
                return;
            }
            var filelist = [];
            for (var i = 0; i < that.imglist.length; i++) {
                filelist.push(that.imglist[i].url);
            }

            var options = {};
            options.action = "savereleasestrips";
            options.RoomID = that.formtwo.RoomID;
            options.ProjectID = that.formtwo.ProjectID;
            options.OwnerName = that.formtwo.OwnerName;
            options.PhoneNumber = that.formtwo.PhoneNumber;
            options.StartTime = moment(that.formtwo.StartTime).format("YYYY-MM-DD HH:mm");//有效开始时间
            options.EndTime = moment(that.formtwo.EndTime).format("YYYY-MM-DD HH:mm");//有效结束时间
            options.VisitType = that.formtwo.VisitType;
            options.ItemInformation = that.formtwo.ItemInformation;
            options.VehicleInformation = that.formtwo.VehicleInformation;
            options.ReleaseInstructions = that.formtwo.ReleaseInstructions;
            options.ApplyCompany = that.formtwo.ApplyCompany;//申请单位
            options.Type = that.formtwo.Type == "2"? 2 : 1;//类型 1-内部单位 2-外部单位

            toast.loading({
                title: "提交中",
                duration: 2000
            }, function (ret) { });
            ns.post(options, function (succeed, data, err) {

                toast.hide();
                if (succeed) {     
                    api.toast({
                        msg: '提交成功',
                        duration: 2000,
                        location: 'bottom'
                    });

                    //刷新并关闭
                    setTimeout(() => {
                        api.sendEvent({
                            name: 'do_load_data',
                        });
                        api.closeWin();
                    }, 300);
                    

                } else if (err) {
                    api.toast({
                        msg: err,
                        duration: 2000,
                        location: 'bottom'
                    });
                }
            }, {
                files: {
                    file: filelist
                }
            });
        },
        //数据
        handleEnterThird(event) {
            // 检查按下的键是否是Enter
            if (event.keyCode == 13) {
                this.doSearch();
            }
        },
        doSearchClearThird() {
            this.formthird.keywords = '';
            this.doSearch();
        },
        get_data_third: function () {
            var that = this;
            var options = {};
            options.pagesize = that.formthird.pagesize;
            options.pageindex = that.formthird.pageindex;
            options.Type = 2;//1-待处理 2-数据
            options.ProjectIDs =JSON.stringify(that.formthird.ProjectIDs);
            options.VisitTypeIDs = JSON.stringify(that.formthird.VisitTypeIDs);
            options.keyWords = that.formthird.keywords;
            options.StartTime = that.formthird.startTime;
            options.EndTime = that.formthird.endTime;
            options.States=JSON.stringify(that.formthird.StatusIDs);
            options.action = "getreleasestripvisitdata";
            ns.post(options, function (succeed, data, err) {
                if (succeed) {
                    that.thirdList = data.list;
                } else if (err) {
                    api.toast({
                        msg: err,
                        duration: 2000,
                        location: 'bottom'
                    });
                }
            }, {
                toast: true
            });
        },
        getSearchParams: function () {
            var that = this;
            var options = {};
            options.action = "getanalysissearchparam";
            ns.post(options, function (succeed, data, err) {
                if (succeed) {
                    that.searchProjectList = data.projectList;
                    // if (that.searchProjectList != undefined && that.searchProjectList.length > 0) {
                    //     that.doSearchProject(that.searchProjectList[0].ID, that.searchProjectList[0].Name);
                    // }
                } else if (err) {
                    api.toast({
                        msg: err,
                        duration: 2000,
                        location: 'bottom'
                    });
                }
            });
        },
        doSearchThird() {
            var that = this;
            that.showsearchparam = !that.showsearchparam;
            this.IsShowSearchThird = !this.IsShowSearchThird;
            if (this.IsShowSearchThird) {
                setTimeout(function () {
                    that.initPicker();
                }, 100);
            }
        },
        doCloseSearchThird() {
            this.showsearchparam = false;
            this.IsShowSearchThird = false;
        },
        doReset: function () {
            var that = this;
            that.formthird.startTime = '';
            that.formthird.endTime = '';
            that.formthird.activeDate = 0;
            that.formthird.ProjectIDs = [];
            that.formthird.VisitTypeIDs = [];
            that.formthird.StatusIDs = [];
        },
        doSearch: function () {
            var that = this;
            that.doCloseSearchThird();
            that.get_data_third();
        },
        doSearchProject: function (ID, Name) {
            var that = this;
            that.formthird.ProjectIDs = [];
            that.formthird.ProjectIDs.push(ID);
        },
        doSearchVisitType: function (ID, Name) {
            var that = this;
            that.formthird.VisitTypeIDs = [];
            that.formthird.VisitTypeIDs.push(ID);
        },
        doSearchStatus: function (ID, Name) {
            var that = this;
            that.formthird.StatusIDs = [];
            that.formthird.StatusIDs.push(ID);
        },
        doClickDay: function (dataValue) {
            var that = this;
            that.formthird.activeDate = dataValue;
            var startDate = '',
                endDate = '';
            if (dataValue == 1) {
                var currentDate = dateRangeUtil.getCurrentDate();
                startDate = moment(new Date()).subtract(3, 'days').format("YYYY-MM-DD");
                endDate = dateRangeUtil.getDateString(currentDate);
            }
            if (dataValue == 2) {
                var currentDate = dateRangeUtil.getCurrentDate();
                startDate = moment(new Date()).subtract(7, 'days').format("YYYY-MM-DD");
                endDate = dateRangeUtil.getDateString(currentDate);
            }
            if (dataValue == 3) {
                var currentDate = dateRangeUtil.getCurrentDate();
                startDate = moment(new Date()).subtract(30, 'days').format("YYYY-MM-DD");
                endDate = dateRangeUtil.getDateString(currentDate);
            }
            that.formthird.startTime = startDate;
            that.formthird.endTime = endDate;
        },
        initPicker: function () {
            var _this = this;
            (function ($, doc) {
                $.init();
                $.ready(function () {
                    //开始日期
                    var btn = document.querySelector('#startdate');
                    btn.addEventListener('tap', function () {
                        var _self = this;
                        if (_self.picker) {
                            if (_this.formthird.startTime) {
                                _self.picker.setSelectedValue(_this.formthird.startTime);//回显
                            }
                            _self.picker.show(function (rs) {
                                _this.formthird.startTime = rs.value;
                                _self.picker.dispose();
                                _self.picker = null;
                            });
                        } else {
                            var optionsJson = this.getAttribute('data-options') || '{}';
                            var options = JSON.parse(optionsJson);
                            var id = this.getAttribute('id');
                            _self.picker = new $.DtPicker(options);
                            if (_this.formthird.startTime) {
                                _self.picker.setSelectedValue(_this.formthird.startTime);//回显
                            }
                            _self.picker.show(function (rs) {
                                var timer = setTimeout(function () {
                                    clearTimeout(timer);
                                    _this.formthird.startTime = rs.value;
                                }, 300);
                                _self.picker.dispose();
                                _self.picker = null;
                            });
                        }
                    }, false);
                    //结束日期
                    var btnEnd = document.querySelector('#enddate');
                    btnEnd.addEventListener('tap', function () {
                        var _self = this;
                        if (_self.picker) {
                            if (_this.formthird.endTime) {
                                _self.picker.setSelectedValue(_this.formthird.endTime);//回显
                            }
                            _self.picker.show(function (rs) {
                                _this.formthird.endTime = rs.value;
                                _self.picker.dispose();
                                _self.picker = null;
                            });
                        } else {
                            var optionsJson = this.getAttribute('data-options') || '{}';
                            var options = JSON.parse(optionsJson);
                            var id = this.getAttribute('id');
                            _self.picker = new $.DtPicker(options);
                            if (_this.formthird.endTime) {
                                _self.picker.setSelectedValue(_this.formthird.endTime);//回显
                            }
                            _self.picker.show(function (rs) {
                                var timer = setTimeout(function () {
                                    clearTimeout(timer);
                                    _this.formthird.endTime = rs.value;
                                }, 300);
                                _self.picker.dispose();
                                _self.picker = null;
                            });
                        }
                    }, false);
                });
            })(mui, document);
        },
    }
});
apiready = function () {
    api.parseTapmode();
    ns = window.Foresight.Util;
    WXPhotoPicker = api.require('WXPhotoPicker');

    setTimeout(function () {
        app.get_data();
    }, 500)
    api.addEventListener({
        name: 'do_choose_project_complete'
    }, function (ret) {
        app.get_select_project(ret.value);
    });

    api.addEventListener({
        name: 'do_load_data'
    }, function (ret, err) {
       app.onClickTab();
    });
};
